using System.Collections.Generic;
using System.Data;
using MallInteractiveMap.ClientDataHandler;
using MallInteractiveMap.Common;
using MallInteractiveMap.DTO;
using System.Linq;
using MallInteractiveMap.Language;

namespace MallInteractiveMap.CMSWebClient.Presenter
{
	public class FloorPresenter
	{
		public FloorPresenter()
		{
		}
		public List<DTOFloor> GetFloors()
		{
			string error = string.Empty;
			List<DTOFloor>floor= ClientData.GetFloor(new QueryParamList(), ref error);
			if (!string.IsNullOrEmpty(error))
			{

			}
			return floor;
		}
		public List<DTOFloor> GetFloors(int Id)
		{
			string error = string.Empty;
			QueryParamList param = new QueryParamList();
			param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32 , ParamValue = Id});
			List<DTOFloor>floor= ClientData.GetFloor(param, ref error);
			if (!string.IsNullOrEmpty(error))
			{

			}
			return floor;
		}
		public bool SetData(DTOFloor oFloor)
		{
			QueryParamList param = new QueryParamList();
            if (!oFloor.IsNew)
            {
                param.Add(new QueryParamObj() {ParamName = "Id", DBType = DbType.Int32, ParamValue = oFloor.Id});
            }
            else
            {
                param.Add(new QueryParamObj() { ParamName = "LanguageType", DBType = DbType.Int32, ParamValue = LanguageLoader.CurrentLanguageType });
            }
		    param.Add(new QueryParamObj(){ParamName="MallId", DBType=DbType.Int32, ParamValue= new MallPresenter().GetMalls().First().Id});
			param.Add(new QueryParamObj(){ParamName="MapId", DBType=DbType.Int32, ParamValue= oFloor.MapId});
			param.Add(new QueryParamObj(){ParamName="Name", DBType=DbType.String, ParamValue= oFloor.Name});
			param.Add(new QueryParamObj(){ParamName="FloorIndex", DBType=DbType.Int32, ParamValue= oFloor.FloorIndex});
			param.Add(new QueryParamObj(){ParamName="Description", DBType=DbType.String, ParamValue= oFloor.Description});
			param.Add(new QueryParamObj(){ParamName="LastUpdated", DBType=DbType.DateTime, ParamValue= oFloor.LastUpdated});
			string error = string.Empty;
			string spName = oFloor.IsNew ? "INSERTFloor " : "UPDATEFloor";
			bool isSuccess = ClientData.SetData(param, spName, ref error);
			return string.IsNullOrEmpty(error) & isSuccess;
		}
		public bool Delete(int Id)
		{
			string error = string.Empty;
			QueryParamList param = new QueryParamList();
			param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32 , ParamValue = Id});
			bool isSuccess = ClientData.SetData(param, "DELETEFloor",  ref error);
			return string.IsNullOrEmpty(error) & isSuccess;
		}
	}
}
